package com.server.process.controller;

import com.server.common.entity.Result;
import com.server.common.entity.ResultCode;
import com.server.domain.process.ProcessEdge;
import com.server.domain.process.ProcessNode;
import com.server.process.service.ProcessEdgeService;
import com.server.process.service.ProcessNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping(value = "/workflow/edges")
public class ProcessEdgeController {
    @Autowired
    private ProcessEdgeService processEdgeService;

    // 新建节点
    @RequestMapping(value = "/new", method = RequestMethod.POST)
    public Result save(@RequestBody ProcessEdge processEdge){
        // 业务操作
        processEdgeService.add(processEdge);
        // 返回Result
        return new Result(ResultCode.SUCCESS);
    }
    // 根据id更新节点
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public Result update(@PathVariable(value = "id") String id, @RequestBody ProcessEdge processEdge) {
        // 业务操作
        processEdge.setId(id);
        processEdgeService.update(processEdge);
        // 返回Result
        return new Result(ResultCode.SUCCESS);
    }
    //根据id查询节点
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Result findById(@PathVariable(value = "id") String id){

        return new Result(ResultCode.SUCCESS, processEdgeService.findById(id));
    }
}
